package com.teatime.client.activity;

import java.util.EmptyStackException;
import java.util.Stack;

public class TActivityManager {
	private static Stack<TActivity> mActivityStack;
	
	public TActivityManager() {
		mActivityStack = new Stack<TActivity>();
	}
	
	public void push(TActivity activity) {
		mActivityStack.push(activity);
	}
	
	public TActivity pop() {
		try {
			return mActivityStack.pop();
		}
		catch(EmptyStackException e) {
			
		}
		return null;
	}
	
	public TActivity popIf(TActivity activity) {
		try {
			if (mActivityStack.peek() == activity) {
				return mActivityStack.pop();
			}
		}
		catch(EmptyStackException e) {
			
		}
		return null;
	}
	
	public void popAll() {
		TActivity a = pop();
		while(a != null) {
			a.finishActual();
			a = pop();
		}
	}
}
